#include <iostream>
#include <algorithm>
using namespace std;

inline void presentArray(const int arr[], const int &n) {
    for (int i = 0; i < n - 1; ++i)
        cout << arr[i] << " ";
    cout << arr[n-1] << endl;
}

int main() {
    int n, arr[10000] = {0};

    cin >> n;
    for (int i = 0; i < n; ++i) cin >> arr[i];

    int cnt = 0;
    bool flag = true;
    int i = 0;
    while (flag) {
        flag = false;
        for (int j = n - 1; j >= i; --j) {
            if (arr[j - 1] > arr[j]) {
                std::swap(arr[j], arr[j - 1]);
                ++cnt;
                flag = true;
            }
        }
        ++i;
    }
    cout << cnt << endl;
    presentArray(arr, n);
    return 0;
}